/*
 * NaviMesh.hpp
 *
 *  Created on: 30/11/2011
 *      Author: Aeradon
 */

#ifndef NAVIMESH_HPP_
#define NAVIMESH_HPP_

#include "navinode.hpp"
#include "triangulation.hpp"

//#ifdef _BUILD_DLL
//   #define DLLDIR  __declspec(dllexport)   // export DLL information
//#else
//   #define DLLDIR  __declspec(dllimport)   // import DLL information
//#endif
//
//class DLLDIR Navimesh
class Navimesh
{
public: /// Definitions
	typedef float	   T;

public: /// Methods
	Navimesh(Triangulation *triangulation);
	virtual ~Navimesh();

	virtual void DestroyMesh();
	virtual void RebuildMesh();

	/// Methods called while building the navimesh
	/// These 5 methods should be overriden if you want to use a custom Navinode
	virtual NaviNode* CreateNode(Face* face);
	virtual void 	  RemoveNode(NaviNode* node);
	virtual void OnSplit(NaviNode* nToSplit, NaviNode* n1, NaviNode* n2, NaviNode* n3){};
	virtual void OnJoin (NaviNode* n1, NaviNode* n2, NaviNode* nJoined){};
	virtual void OnFlip (NaviNode* n1, NaviNode* n2){};

	virtual NaviNode* LocateOrCreateNode(Face* face);
	virtual NaviNode* LocateNode(Face* face);

	std::list<Point<T> > pathFind(T stt_x, T stt_y, T dst_x, T dst_y);
	std::list<T> pathFindXY(T stt_x, T stt_y, T dst_x, T dst_y);
	void ClearPathInfo();
	void PrintPath(std::list<T>& l_coord);
	void PrintPath(std::list<Point<T> >& l_point);

	T Heuristic(NaviNode* stt, NaviNode* dst);
	NaviNode* LowestFIn(std::list<NaviNode*>& l_open);
	bool IsInList(NaviNode* n, std::list<NaviNode*>& l_node);
	std::list<Point<T> > BuildPointPath(NaviNode* dst);
//	void CalculateSymEdgeNormals();

#ifdef _DEBUG
	void printPath(std::list<Navimesh::T>& l_coord);
	void printPath(std::list<Point<Navimesh::T> >& l_point);
#endif

protected: /// Atributes
	std::vector<NaviNode*> v_node;

	Triangulation *tri;
};

#endif /* NAVIMESH_HPP_ */
